<?php

namespace app\controller;

use app\Request;
use Gregwar\Captcha\CaptchaBuilder;
use think\facade\Session;

class CaptchaController
{
    public function generate()
    {
        $builder = new CaptchaBuilder();
        $builder->build();
        $phrase = $builder->getPhrase();
        Session::set('captcha', $phrase);

        header('Content-type: image/jpeg');
        return response($builder->output(), 200, ['Content-Type' => 'image/jpeg']);
    }

    public function verify($code)
    {
        $captcha = Session::get('captcha');
        if (strtolower($code) === strtolower($captcha)) {
            return true;
        } else {
            return false;
        }
    }
}